package com.jd.cs.config;

import com.jd.cs.config.interceptor.JWTTokenInterceptor;
import com.jd.cs.config.interceptor.ClearInterceptor;
import com.jd.cs.config.interceptor.LangInterceptor;
import com.jd.cs.config.interceptor.TokenInterceptor;
import org.springframework.context.annotation.Configuration;
import org.springframework.web.servlet.config.annotation.InterceptorRegistry;
import org.springframework.web.servlet.config.annotation.WebMvcConfigurationSupport;

import javax.annotation.Resource;

/**
 * @author: lizhiwei
 * @date: 2020-07-25 20:27
 **/
@Configuration
public class WebMvcConfiguration extends WebMvcConfigurationSupport {
    @Resource
    private TokenInterceptor tokenInterceptor;
    @Resource
    private LangInterceptor langInterceptor;
    @Resource
    private ClearInterceptor clearInterceptor;
    @Resource
    private JWTTokenInterceptor jwtTokenInterceptor;

    private static final String[] excludePathPatterns = {"/token/*"};

    @Override
    protected void addInterceptors(InterceptorRegistry registry) {
        super.addInterceptors(registry);
        registry.addInterceptor(langInterceptor).addPathPatterns("/**");
        //registry.addInterceptor(tokenInterceptor).addPathPatterns("/**").excludePathPatterns(excludePathPatterns);
        registry.addInterceptor(jwtTokenInterceptor);
        registry.addInterceptor(clearInterceptor).addPathPatterns("/**");
    }
}